package com.sky.controller.user;

import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userCategoryController")
@RequestMapping("/user/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/list")
    public Result<List<Category>> list(Integer type ) {
        //如果type为空,查询全部分类
        if (type == null) {
            List<Category> categories = categoryService.getAllCategory();
            return Result.success(categories);
        }

        //查询所有分类
        List<Category> categories = categoryService.getByType(type);
        return Result.success(categories);
    }
}
